package com.lindroy.keyboarddemo

import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.EditText
import androidx.appcompat.app.AppCompatActivity
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.view.updateLayoutParams
import com.lindroy.keyboarddemo.util.keyboard.KeyboardStatusWatcher
import com.lindroy.keyboarddemo.util.keyboard.hideKeyboard

class MainActivity : AppCompatActivity() {
    private val clRoot by lazy { findViewById<ConstraintLayout>(R.id.clRoot) }
    private val vKeyboardBg by lazy { findViewById<View>(R.id.vKeyboardBg) }
    private val editText by lazy { findViewById<EditText>(R.id.editText) }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        clRoot.setOnClickListener { editText.hideKeyboard() }

        KeyboardStatusWatcher(this,this) { isKeyboardShowed: Boolean, keyboardHeight: Int ->
            vKeyboardBg.updateLayoutParams<ConstraintLayout.LayoutParams> {
                bottomMargin = keyboardHeight
            }
            Log.d("Tag", "isShowed = $isKeyboardShowed,keyboardHeight = $keyboardHeight")
        }
    }
}